/**$Licence:
 *   Use this however/wherever you like, just don't blame me if it breaks anything.
 *   Copyright (C) 2008 - 2011 xingsheng.zhu@gmail.com All rights reserved.
 */
package com.blazemina.commonchain;

import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.config.ConfigParser;
import org.apache.commons.chain.impl.CatalogFactoryBase;
import org.apache.commons.chain.impl.ContextBase;

/**
 * 通过XML来配置Command
 * 
 * @author JackChu
 * @version 1.0.0 2011-12-23 下午4:21:56
 */
public class XMLCommandChain {

	private static final String XML_CONFIG = "commonchain/chain.xml";

	public static void main(String[] args) throws Exception {
		ConfigParser parser = new ConfigParser();

		parser.parse(XMLCommandChain.class.getClassLoader().getResource(
				XML_CONFIG));

		Catalog catalog = CatalogFactoryBase.getInstance().getCatalog();
		// 加载Chain
		Command cmd = catalog.getCommand("sell-vehicle");
		Context ctx = new ContextBase();
		cmd.execute(ctx);
		// 加载Command
		cmd = catalog.getCommand("GetCustomerInfo");
		cmd.execute(ctx);

	}

}
